package com.tuozixuan.caffeine;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;

public class AutoDemo {

	public static void main(String[] args) {
		
		 LoadingCache<String, String> cache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(10_000).build(key -> {return "lisi";});
		
		String key = "name";
		
		// 查找缓存，如果缓存不存在则生成缓存元素,  如果无法生成则返回null
		String name = cache.get(key);
		System.out.println("name:" + name);
		
		// 批量查找缓存，如果缓存不存在则生成缓存元素
		List<String> keys = Arrays.asList(key);
		Map<String, String> map = cache.getAll(keys);
		System.out.println("map:" + map);
	}

}
